package Demo1;

public class T7 {
    private static volatile boolean isQuit = false;//标志位

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
//            lambda 表达式本质上是 函数式接口 -->匿名内部类
            while (!isQuit) {
                System.out.println("线程工作中");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("线程结束!");
        isQuit = true;
    }

}
